/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package net.worlds.lua.metatable;

import net.worlds.lua.Event;
import se.krka.kahlua.vm.JavaFunction;
import se.krka.kahlua.vm.LuaCallFrame;

/**
 *
 * @author Jacob
 */
public class EventMetatable {
    public static class EventIndex implements JavaFunction
    {
        public int call(LuaCallFrame callFrame, int nArguments) {
            final Event evt = (Event) callFrame.get(0);
            String k = callFrame.get(1).toString();
            if(k.equals("enable"))
                callFrame.push(new JavaFunction()
                {
                    public int call(LuaCallFrame callFrame, int nArguments) {
                        evt.disabled = false;
                        return 0;
                    }
                });
            else if(k.equals("disable"))
                callFrame.push(new JavaFunction()
                {
                    public int call(LuaCallFrame callFrame, int nArguments) {
                        evt.disabled = true;
                        return 0;
                    }
                });
            else
                throw new RuntimeException(k+"is not a member of "+evt.eventName);
            return 1;
        }
    }
}
